package com.ukao.cashregister.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.cashregister.R;
import com.ukao.cashregister.bean.UserInfoBean;
import com.ukao.cashregister.listener.OnItemChildClickListener;
import com.ukao.cashregister.utils.CheckUtils;
import com.ukao.cashregister.utils.ImageUtils;
import com.ukao.cashregister.utils.MyDateUtils;
import com.ukao.cashregister.widget.StateButton;

import java.util.List;

import butterknife.BindView;

/**
 * VIP  组员列表
 */

public class VipListAdapter extends CommonAdapter<UserInfoBean.UserBean> {


    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.createTime)
    TextView createTime;
    @BindView(R.id.balance)
    TextView balance;
    @BindView(R.id.phone)
    TextView phone;
    @BindView(R.id.point)
    TextView point;
    @BindView(R.id.usergroup_name)
    TextView usergroupName;
    @BindView(R.id.userCard_name)
    TextView userCardName;
    @BindView(R.id.tagList_name)
    TextView tagListName;

    public VipListAdapter(Context context, List<UserInfoBean.UserBean> datas) {
        super(context, datas, R.layout.adapter_vip_list);
    }

    private OnItemChildClickListener mOnItemChildClickListener;
    public  void  setOnItemChildClickListener(OnItemChildClickListener mOnItemChildClickListener){
        this.mOnItemChildClickListener=mOnItemChildClickListener;
    }

    @Override
    public void convert(final ViewHolder holder, UserInfoBean.UserBean item) {

        TextView name=holder.getView(R.id.name);
        TextView createTime=holder.getView(R.id.createTime);
        TextView balance=holder.getView(R.id.balance);
        TextView phone=holder.getView(R.id.phone);
        TextView point=holder.getView(R.id.point);
        TextView cardNo=holder.getView(R.id.card_no);
        TextView usergroupName=holder.getView(R.id.usergroup_name);
        TextView tagListName=holder.getView(R.id.tagList_name);
        TextView userCardname=holder.getView(R.id.userCard_name);
        ImageView headimgPath=holder.getView(R.id.headimgPath);
        StateButton rechargeBtn=holder.getView(R.id.recharge_btn);
        StateButton placeOrderBtn=holder.getView(R.id.place_order_btn);



        UserInfoBean.UserBean.InfoBeanX useInfo = item.getInfo();
        phone.setText(!CheckUtils.isEmpty(useInfo.getPhone())==true ? useInfo.getPhone() :"");/*手机*/
        name.setText(useInfo.getName());/*用户名*/
        createTime.setText(!CheckUtils.isNull(useInfo.getCreateTime())?  "创建时间："+ MyDateUtils.formatDataTime(useInfo.getCreateTime()) :"创建时间：");
        UserInfoBean.UserBean.ExtBean extItem = item.getExt();
        balance.setText("余额："+CheckUtils.isEmptyNumber(extItem.getBalance())+"元");
        point.setText("积分："+extItem.getPoint());
        UserInfoBean.UserBean.GroupBean muserGroupItem = item.getGroup();
        usergroupName.setText(!CheckUtils.isEmpty(muserGroupItem.getName())==true ?"分组："+muserGroupItem.getName():"分组：");  /*分组*/

        UserInfoBean.UserBean.CardBean cardItem = item.getCard();
        if (!CheckUtils.isNull(cardItem)){
            cardNo.setText(!CheckUtils.isEmpty(cardItem.getNo())==true ?cardItem.getNo():"");  /*卡号*/
            ImageUtils.loadImage(mContext,useInfo.getHeadimgPath(),headimgPath);
            userCardname.setText(!CheckUtils.isEmpty(cardItem.getInfo().getName())==true ?"等级："+cardItem.getInfo().getName()+"  "+cardItem.getInfo().getDiscount():"等级："+cardItem.getInfo().getDiscount());  /*卡号*/
            List<UserInfoBean.UserBean.TagListBean> mTagData = item.getTagList(); /*标签集合*/
            if (!CheckUtils.isEmpty(mTagData)){
                String tag="";
                for (int i = 0; i < mTagData.size(); i++) {

                    UserInfoBean.UserBean.TagListBean.UserTagBean userTag = mTagData.get(i).getUserTag();
                    if (!CheckUtils.isNull(userTag)){
                        String   strname=userTag.getName();
                        switch (i){
                            case 0  :
                                tag+=strname;
                                break;
                            case 1  :
                                tag+="/"+strname;
                                break;
                            case 2  :
                                tag+="/"+strname;
                                break;
                        }
                    }

                }
                tagListName.setText("标签："+tag);
            }else{
                tagListName.setText("标签：");
            }
        }








        View.OnClickListener   mOnClickListene=new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                if (mOnItemChildClickListener!=null){
                    mOnItemChildClickListener.onChildItemClick(v.getId(),getPosition(holder));
                }
            }
        };

        placeOrderBtn.setOnClickListener(mOnClickListene);
        rechargeBtn.setOnClickListener(mOnClickListene);
    }



}
